<template>
  <div>
    <div style="width:30%">
      <h3>新专业申请</h3>
      <Divider style="height: 2px;margin:15px 0;display: inline-block;" />
    </div>
    <div style="width:80%">
      <h4 style="float: left">申报信息填写</h4>
      <Button id="b1" @click="exit()">退出</Button>
      <Divider style="height: 2px;margin:15px 0;display: inline-block;" />
    </div>
    <Form style="width: 60%;" ref="formMajor" :model="formMajor" :rules="ruleMajor" :label-width="120">
      <FormItem label="审核意见" prop="nmdApprovalopi">
        <Input v-model="formMajor.nmdApprovalopi"></Input>
      </FormItem>
      <FormItem label="审核人" prop="nmdApprover">
        <Input v-model="formMajor.nmdApprover"></Input>
      </FormItem>
      <FormItem>
        <Button type="primary" @click="handleSubmit('formMajor')">提交申请</Button>
      </FormItem>
    </Form>
  </div>
</template>

<script>
  export default {
    data() {
      return {
        formMajor: {
          scId: '',
          nmId: '',
          nmdName: '',
          nmdApplydate: '',
          nmdApprovalopi: '',
          nmdApprovaldate: '',
          nmdApprover: '',
          nmdState: ''
        },
        ruleMajor: {
          nmdApprovalopi: [{
            required: true,
            message: '审核意见不能为空',
            trigger: 'blur',
          }],
          nmdApprover: [{
            required: true,
            message: '审核人不能为空',
            trigger: 'blur',
          }]
        },
        nmList: []
      }
    },
    created() {
      this.getParams()
    },
    watch: {
      '$route': 'getParams'
    },
    methods: {
      getParams() {
        this.nmList = this.$route.query.nmList
      },
      handleSubmit(name) {
        var d = new Date()
        this.formMajor.nmdApprovaldate = d.toISOString()
        console.log(d.toISOString())
        this.$refs[name].validate((valid) => {
          if (valid) {
            this.$axios.post(this.$host + '/professional/declaration/newMajorDeclaration', {
              scId: this.nmList.scId,
              nmId: this.nmList.nmId,
              nmdName: this.nmList.nmdName,
              nmdApplydate: this.nmList.nmdApplydate,
              nmdApprovalopi: this.formMajor.nmdApprovalopi,
              nmdApprovaldate: this.formMajor.nmdApprovaldate,
              nmdApprover: this.formMajor.nmdApprover,
              nmdState: '已审批'
            }).then(res => {
              console.log(res)
              if (res.data.message == '提交新专业申请审批信息成功') {
                this.$Message.success('提交新专业审核信息成功!');
                this.$router.push({
                  name: 'NewMajor'
                })
              } else {
                this.$Message.error('提交新专业申报信息失败!');
              }
            })
          }
        })
      },
      exit () {
        this.$router.push({
          name: 'NewMajor'
        })
      }
    }
  }
</script>

<style scoped>
  h3 {
    font-size: 1.75rem;
    float: left;
  }

  #b1 {
    float: right;
    background-color: burlywood;
  }

  #b2 {
    background-color: cadetblue;
  }
</style>
